 $().ready(function() {

	/* var addNewSpan = '<span id="errormsg_container"></span>';
        $("#announcements-node-form").before(addNewSpan);*/
	
  $("#press-releases-node-form").validate({
										/* onfocusout: false,
  										 onkeyup: false,
  										 onclick: false,*/
										 //debug:true,
										 
					rules: {
						'field_press_dept[und]': { 
							required: true,
							maxlength: 255,
							chkbadchar:true,
							valuenotequals: '_none',
						},
						'field_press_organization[und]': { 
							required: true,
							maxlength: 255,
							chkbadchar:true,
							valuenotequals: '_none',
						},
						'field_press_district[und][]':{
							//required: true,
							//maxlength: 255,
							//chkbadchar:true,
							multi_dist_select: true,
							
							},
						'title': { 
							required: true,
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,
						},
						'field_press_number[und][0][value]':{
							required: "#edit-field-press-availability-und-download:checked",
							minlength: 0,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,							
						},
						
						
						'field_press_date[und][0][value][date]':{
							required: true,
							dateformat:true,
							date_notgreater_tdy:true,
							//date_greater_than:{ 'compar_id':'#edit-field-announcement-date-und-0-value2-datepicker-popup-0' },
						},

						'field_press_details[und][0][value]':{
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,							
						},

						'field_press_availability[und]': { 
							required: true,
						},
					
						'field_press_url[und][0][value]':{
							required: "#edit-field-press-availability-und-online:checked",
							url: true,
							chkbadchar:true,


						},
						'files[field_press_upload_und_0]':{
							required: "#edit-field-press-availability-und-download:checked",
							//required: true,
							chkfile_format_size: true,
						},
						'files[field_press_photos_und_0]':{
							required: "#edit-field-press-availability-und-none:checked",
							//required: true,
							//chkfile_format_size: true,
						},
						'field_press_keywords[und][0][value]':{
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,							
						},
						
						
											
					},
                    messages: {
							'field_press_dept[und]':{
							required: 'Please Select Concerned Department',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar: 'insert, select, update, delete, drop, alter, change, modify not allowed.',
							valuenotequals: 'Please Select Concerned Department',
							},
							'field_press_organization[und]':{
							required: 'Please Select Concerned Organization',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar: 'insert, select, update, delete, drop, alter, change, modify not allowed.',
							valuenotequals: 'Please Select Concerned Organization',
							},
							
							'field_press_district[und][]':{
							required: 'Please Select Districts',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							multi_dist_select: 'Please Select either All or Particular Districts',
							},
							'title': { 
							required:  'Please enter Title',
							minlength: 'Minimum 5 characters should be entered',
							maxlength: 'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',
							},

							'field_press_number[und][0][value]':{
							required:  'If Availability of press releses is downloadble, PR No is Required',
							minlength: 'Minimum 5 characters should be entered',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',						
							},

							'field_press_details[und][0][value]':{
							required:  'Details Value is Required',
							minlength: 'Minimum 5 characters should be entered',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',						
							},
							'field_press_date[und][0][value][date]':{
							required:'Please enter Press Release Date',
							dateformat: 'Invalid Date format',
							date_notgreater_tdy: 'Press Release Date should not be greater than today date.',
							//date_greater_than:{ 'compar_id':'#edit-field-announcement-date-und-0-value2-datepicker-popup-0' },
							},
							
							'field_press_availability[und]': { 
							required: 'Please select Press Release available type',
							maxlength:  'Invalid option',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							},
							'field_press_url[und][0][value]':{
							required: "Please Enter URL",
							url: 'Not Valid URL',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							},
							'files[field_press_upload_und_0]':{
							required: 'Please select upload file',
							chkfile_format_size: 'Invalid File Format',
							},
							'files[field_press_photos_und_0]':{
							required: 'If Avaialability of Press Relese is none, upload photos is required',
							chkfile_format_size: 'Invalid File Format',
							},
							'field_press_keywords[und][0][value]':{
							required: 'Please enter press release keywords',
							minlength: 'Minimum 5 characters should be entered',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',					
							},
	
				}, 
					errorLabelContainer: "#errormsg_container",
					 //focusInvalid: false,
   					invalidHandler: function(form, validator) {
       
       					 if (!validator.numberOfInvalids())
								return;
						else{
							
							  $("#press-releases-node-form").create_errormsg_container('errormsg_container','press-releases-node-form');
						}
							
							$('html, body').animate({
								scrollTop: $(validator.errorList[0].element).offset().top - 100
							}, 1000);
							
						},
				

   
	});

            
});
